/*
 * --------------------------------------------------------------------
 * @name IniFilesReader.java
 * @author Juan Camilo Ibarra
 *
 * This work is licensed under a Creative
 * Commons Attribution 3.0 License. This means you can to copy, 
 * distribute, transmit and adapt the work, under the following condition:
 * You must attribute the work in the manner specified by the author or licensor.
 *
 * Juan Camilo Ibarra	-	ju-ibarr@uniandes.edu.co
 *
 * IMAGINE research group
 * Universidad de los Andes
 * Sep 12, 2011
 * --------------------------------------------------------------------
 */
package util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
 * Reads an ini file. An ini file is a simple configuration file where in each line there is 
 * <br> a parameter defined as parameter = value
 * @author juanibarral
 *
 */
public class IniFilesReader {
	/**
	 * Reads a configuration file in ini format
	 * @param filePath filepath for the configuration file
	 * @return a map with the parameters in the file
	 * @throws IOException if the file does not exist
	 */
	public static Map<String, String> readIniFile(String filePath) throws IOException
	{
		Map<String, String> propertiesMap = new HashMap<String, String>();
		File file = new File(filePath);
		FileInputStream inStream = new FileInputStream(file);
		Properties properties = new Properties();
		properties.load(inStream);
		
		Enumeration<?> enumerationSet = properties.propertyNames();
		
		
		while(enumerationSet.hasMoreElements())
		{
			String key = (String) enumerationSet.nextElement();
			propertiesMap.put(key, properties.getProperty(key));
		}
		return propertiesMap;
	}
}
